﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Qianli.DirSir.Common;
using Qianli.DirSir.Model;
using System.Data;

namespace Qianli.DirSir.DAL
{
    public class UserDAL
    {
        SQLHelper sqlhelper = new SQLHelper();
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="u">前台传过来的用户集合</param>
        /// <returns></returns>
        public int Login(Userinfo u)
        {
            string sql = "select * from Userinfo where UserName='" + u.UserName + "'";
            DataTable dt = sqlhelper.ExecDataTable(sql);
            if (dt.Rows[0].ToString() != "")
            {
                if (dt.Rows[0][4].ToString() == u.UserPass)
                {
                    return 1;//代表登录成功
                }
                else
                {
                    return 0;//代表密码错误
                }
            }
            else
            {
                return 2;//代表用户名不存在
            }

        }
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="u"></param>
        /// <returns></returns>
        public int Register(Userinfo u)
        {
            u.RoleID = 1;
            u.UserState = 1;
            string sql = "insert into Userinfo(RoleID,ParenCompanyName,UserName,UserPass,UserState) values("+u.RoleID+",'"+u.ParenCompanyName+"','"+u.UserName+"','"+u.UserPass+"',"+u.UserState+")";
            return sqlhelper.ExecNonquery(sql);
        }
    }
}
